package top.rish.converter.core.annotation.handler;

import top.rish.converter.core.annotation.Kv;
import top.rish.converter.core.annotation.KvConverter;
import top.rish.converter.core.base.DictEntity;
import top.rish.converter.core.info.FieldWrap;
import top.rish.converter.core.info.MetaMap;

import java.util.Objects;

public class KvConverterHandlerDict implements DictConvertHandler<KvConverter> {
    @Override
    public void convert(MetaMap mateMap,
                        DictEntity entity,
                        Object value,
                        FieldWrap fieldWrap, KvConverter convert) {
        for (Kv kv : convert.value()) {
            if(Objects.toString(value).equals(kv.k())){
                mateMap.set(fieldWrap.getName()+"Name", kv.v());
                return;
            }
        }
        mateMap.set(fieldWrap.getName()+"Name", null);
    }
}
